package com.example.bpmn.service;

import com.example.bpmn.event.ProcessEvent;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.util.Map;

@Slf4j
@Service
@RequiredArgsConstructor
public class ProcessEventPublisher {
    
    private final KafkaTemplate<String, Object> kafkaTemplate;
    private static final String TOPIC = "process_events";

    public void publishEvent(String eventName, String businessKey, String processInstanceId) {
        ProcessEvent event = ProcessEvent.builder()
            .eventName(eventName)
            .businessKey(businessKey)
            .processInstanceId(processInstanceId)
            .timestamp(System.currentTimeMillis())
            .build();
            
        kafkaTemplate.send(TOPIC, businessKey, event);
        log.info("事件已发布: {}", event);
    }

    public void publishProcessStarted(String businessKey, Map<String, Object> variables) {
        log.info("发布流程启动事件: businessKey={}, variables={}", businessKey, variables);
        // TODO: 实现实际的事件发布逻辑
    }

    public void publishStatusChanged(String businessKey, Map<String, Object> variables) {
        log.info("发布状态变更事件: businessKey={}, variables={}", businessKey, variables);
        // TODO: 实现实际的事件发布逻辑
    }
} 